import { defineConfig ,loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import vitePluginForArco from '@arco-plugins/vite-vue'
import Components from 'unplugin-vue-components/vite';
import { ArcoResolver } from 'unplugin-vue-components/resolvers';
const { resolve } = require('path')
// https://vitejs.dev/config/
export default defineConfig(({mode})=>{
  const __DEV__ = mode === 'development'
  const base=loadEnv(mode, process.cwd()).VITE_BASE
  console.log(base)
  return {
    plugins: [vue(),
      vitePluginForArco({
        theme:'@arco-themes/vue-mgo-blog'
      }),
      Components({
        resolvers: [
          ArcoResolver({
            importStyle:"less",
            resolveIcons:true
          }),
        ]
      })],
    base:base,
    build:{
        outDir:__DEV__?"./dist":'../'
    },
    server: {
      open: '/',
      host: '0.0.0.0'	,
      proxy: {
          '/mgo-music': {
              target: "http://localhost:8080/mgo-music",
              changeOrigin: true,
              rewrite: (path) => path.replace(/^\/mgo-music/, '')
            },
          '/music': {
              target: "https://music.liuzhijin.cn",
              changeOrigin: true,
              rewrite: (path) => path.replace(/^\/music/, '')
            }
      }
    },
    resolve: {
      alias: [//配置别名
       { find: '@', replacement: resolve(__dirname, 'src') },
       { find: '@views', replacement: resolve(__dirname, 'src/views') }
      ],
      // 情景导出 package.json 配置中的exports字段
      conditions: [],
      // 导入时想要省略的扩展名列表
      // 不建议使用 .vue 影响IDE和类型支持
      extensions:['.mjs','.js','.ts','.jsx','.tsx','.json']  
     },
  }
})
